package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.INavigationDao;
import com.cn.wanxi.model.NavigationModel;
import com.cn.wanxi.util.GetSqlSession;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NavigationDaoImpl implements INavigationDao {
//    JDBC jdbc=new JDBC();
    @Override
    public List<NavigationModel> findAll() {
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.INavigationDao.findAll");
//        String sql="SELECT * FROM navigation;";
//        ResultSet resultSet=jdbc.getResultSet(sql);
//        List<NavigationModel> list=new ArrayList<>();
//        try {
//            while (resultSet.next()){
//                NavigationModel navigationModel=new NavigationModel();
//                navigationModel.setId(resultSet.getInt("id"));
//                navigationModel.setName(resultSet.getString("name"));
//                navigationModel.setConnection(resultSet.getString("connection"));
//                list.add(navigationModel);
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        jdbc.closeConn();
//        return list;
    }

    @Override
    public int deleteById(int navigationid) {
        return GetSqlSession.getSqlSession().delete("com.cn.wanxi.dao.INavigationDao.deleteById",navigationid);
//        String sql="DELETE FROM `navigation` WHERE id= " + navigationid;
//        int count=jdbc.update(sql);
//        jdbc.closeConn();
//        return count;
    }

    @Override
    public NavigationModel findById(int navigationid) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.INavigationDao.findById",navigationid);
//        String sql="SELECT * FROM `navigation` WHERE id = " + navigationid;
//        ResultSet resultSet=jdbc.getResultSet(sql);
//        NavigationModel navigationModel=new NavigationModel();
//        try {
//            while (resultSet.next()){
//                navigationModel.setId(resultSet.getInt("id"));
//                navigationModel.setName(resultSet.getString("name"));
//                navigationModel.setConnection(resultSet.getString("connection"));
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        jdbc.closeConn();
//        return navigationModel;
    }

    @Override
    public int update(NavigationModel navigationModel) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.INavigationDao.update",navigationModel);
//        String sql="UPDATE navigation SET name='"+navigationModel.getName()+"' , connection= '"+navigationModel.getConnection()+"' where id = '"+navigationModel.getId()+"'";
//        int resultSet=jdbc.update(sql);
//        jdbc.closeConn();
//        return resultSet;
    }

    @Override
    public int navigationAdd(NavigationModel navigationModel) {
        return GetSqlSession.getSqlSession().insert("com.cn.wanxi.dao.INavigationDao.navigationAdd",navigationModel);
//        String sql="INSERT INTO navigation (name,connection) VALUES ('"+navigationModel.getName()+"' , '"+navigationModel.getConnection()+"')";
//        int resultSet=jdbc.update(sql);
//        jdbc.closeConn();
//        return resultSet;
    }

}
